import Vue from 'vue'
import router from '../router/index.js'

const logreg = {
	namespaced: true,
	state: () => ({
		account: [
			{
				username: 'admin',
				password: '123456',
				phone: '666'
			},
			{
				username: '陈烨',
				password: '123123',
				phone: '123123'
			},
			{
				username: '钟易辰',
				password: '456456',
				phone: '456456'
			},
			{
				username: '黄承智',
				password: '789789',
				phone: '789789'
			}
		],	//账号信息
		showlogin: false,  //是否显示登录页面
		logining: true, //判断是否在登录 
		logintips: '', //登录过程提示信息
		registertips: '', //注册过程提示信息
		active_user: '',
	}),
	getters: {
	},
	mutations: {
		showlogreg: function(state,bool){
			state.showlogin = bool
		},
		setlogin:function(state,bool){
			state.logining = bool
		},
		setlogintips(state, tips) {
			state.logintips = tips
		},
		setregistertips(state, tips) {
			state.registertips = tips
		},
		// 注册操作
		// userinfo 格式：
		// {
		// 	username: '',
		// 	password: '',
		// 	phone: ''
		// }
		register(state, userinfo) {
			state.account.push(userinfo)
		},
		// 登陆操作
		setactive_user(state, username){
			state.active_user = username
		},
		// 清除active_user，退出登陆
		signout(state){
			// 清楚当前登录用户状态
			state.active_user = '';
			// 删除持久化本地用户登录状态
			localStorage.removeItem('user');
			Vue.prototype.$message({
				type: 'info',
				message: '退出成功',
				center: true,
				duration: 3000
			})
			this.commit('cart/recount_num');
			router.push('/home')
		}
	},
	actions: {
		
	}
}

export default logreg;


/* const user = {
	user: null,
}
// mutations
const mutations = {
	saveUser(state,{username,id}){
		state.user = {username,id}
	},
	deleteUser(state){
		state.user = null;
	}
}

export default {
	namespaced: true,
	state,
	mutations,
} */
